﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Abstract;
using Domain.Entity;
using System.Data;

namespace Domain.Concrete
{
    public class EFMetaScoreRepository : IMetaScoreRepository
    {
        public EFDbContext Context { get; set; }

        public EFMetaScoreRepository()
        {
            Context = EFDbContext.Instance;
        }

        public EFMetaScoreRepository(EFDbContext context)
        {
            Context = context;
        }

        public IQueryable<MetaScore> MetaScores
        {
            get { return Context.MetaScores; }
        }

        public void Save(MetaScore score)
        {
            if (score.Id == 0)
                Context.MetaScores.Add(score);
            else
                Context.Entry(score).State = EntityState.Modified;


            Context.SaveChanges();
        }

        public IQueryable<MetaScore> FindScoresByGameId(int gameId)
        {
            return Context.MetaScores.Where(s => s.GameId == gameId);
        }
    }
}
